home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / info / lispref.info-13 < prev    next >
Encoding:
GNU Info File  |  1995-09-01  |  49.3 KB  |  1,272 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo-1.63
  2. from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995
  12.  
  13.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  14. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  15. Copyright (C) 1995 Amdahl Corporation.  Copyright (C) 1995 Ben Wing.
  16.  
  17.    Permission is granted to make and distribute verbatim copies of this
  18. manual provided the copyright notice and this permission notice are
  19. preserved on all copies.
  20.  
  21.    Permission is granted to copy and distribute modified versions of
  22. this manual under the conditions for verbatim copying, provided that the
  23. entire resulting derived work is distributed under the terms of a
  24. permission notice identical to this one.
  25.  
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that this permission notice may be stated in a
  29. translation approved by the Foundation.
  30.  
  31.    Permission is granted to copy and distribute modified versions of
  32. this manual under the conditions for verbatim copying, provided also
  33. that the section entitled "GNU General Public License" is included
  34. exactly as in the original, and provided that the entire resulting
  35. derived work is distributed under the terms of a permission notice
  36. identical to this one.
  37.  
  38.    Permission is granted to copy and distribute translations of this
  39. manual into another language, under the above conditions for modified
  40. versions, except that the section entitled "GNU General Public License"
  41. may be included in a translation approved by the Free Software
  42. Foundation instead of in the original English.
  43.  
  44. 
  45. File: lispref.info,  Node: Specification Examples,  Prev: Backtracking,  Up: Macro Calls
  46.  
  47. Specification Examples
  48. ......................
  49.  
  50.    This section provides several examples of Edebug specifications to
  51. show most of its capabilities.
  52.  
  53.    A `let' special form has a sequence of bindings and a body where
  54. each of the bindings is a symbol or a sublist with a symbol and optional
  55. value.  In the specification below notice the `fence' inside of the
  56. sublist to prevent backtracking.
  57.  
  58.      (def-edebug-spec let
  59.        ((&rest
  60.          &or symbolp (fence symbolp &optional form))
  61.         body))
  62.  
  63.    Here are the specifications for the `case' and `do' macros in
  64. `cl.el'.  (Specifications for all the macros defined by `cl.el'
  65. (version 2.02) are in `cl-specs.el'.)
  66.  
  67.      (def-edebug-spec case (form &rest (sexp body)))
  68.      
  69.      (def-edebug-spec do
  70.       ((&rest &or symbolp (symbolp &optional form form))
  71.        (form body) body))
  72.  
  73.    Edebug uses the following specifications for `defun' and `defmacro'
  74. and the associated argument list and `interactive' specifications.  It
  75. is necessary to specially process the argument of an interactive form
  76. to allow debugging of a list argument outside of the function body,
  77. while not stopping on the interactive form itself.
  78.  
  79.      (def-edebug-spec defmacro defun)      ; Indirect ref to `defun' spec
  80.      (def-edebug-spec defun
  81.        (&define name lambda-list
  82.                 [&optional stringp]        ; Match the doc string, if present.
  83.                 [&optional ("interactive" interactive)]
  84.                 def-body))
  85.      
  86.      (def-edebug-spec lambda-list
  87.        (([&rest arg]
  88.          [&optional ["&optional" arg &rest arg]]
  89.          &optional ["&rest" arg]
  90.          )))
  91.      
  92.      (def-edebug-spec interactive
  93.        (&optional &or stringp def-form))    ; Notice: `def-form'
  94.  
  95.    The `backquote' specification illustrates how to use `nil' to
  96. terminate recursion.  Also a vector may be matched.
  97.  
  98.    Note that backquote (``') is a macro that results in an expression
  99. that is not necessarily evaluated.  It is often used to simplify the
  100. definition of a macro where the result of the macro call is evaluated,
  101. but Edebug does not know when this is the case.  So do not be surprised
  102. when you cannot step through your backquoted code.  However, `,' and
  103. `,@' forms within backquoted forms are evaluated and Edebug instruments
  104. them.
  105.  
  106.    Nested backquotes are supported to a limited extent.  Quoted forms
  107. are not normally evaluated, but if the quoted form appears immediately
  108. within `,' and `,@' forms, Edebug treats this as a backquoted form at
  109. the next higher level.
  110.  
  111.      (def-edebug-spec ` (backquote-form))
  112.      
  113.      (def-edebug-spec backquote-form
  114.        (&or ([&or "," ",@"] &or ("quote" backquote-form) form)
  115.             (backquote-form . [&or nil backquote-form])
  116.             (vector &rest backquote-form)
  117.             sexp))
  118.  
  119.    Finally, the standard functions `mapcar', `mapconcat', `mapatoms',
  120. `apply', and `funcall' all take function arguments.  Here is one
  121. example:
  122.  
  123.      (def-edebug-spec apply (function-form &rest form))
  124.  
  125. 
  126. File: lispref.info,  Node: Edebug Options,  Prev: Macro Calls,  Up: Edebug
  127.  
  128. Edebug Options
  129. --------------
  130.  
  131.    These options affect the behavior of Edebug:
  132.  
  133.  - User Option: edebug-setup-hook
  134.      Functions to call before Edebug is used.  Each time it is set to a
  135.      new function, Edebug will call that function once and then
  136.      `edebug-setup-hook' is reset to `nil'.  You could use this to load
  137.      up Edebug specifications associated with a package you are using
  138.      only when you also use Edebug.
  139.  
  140.  - User Option: edebug-all-defs
  141.      If non-`nil', normal evaluation of any defining forms (e.g.
  142.      `defun' and `defmacro') will instrument them for Edebug.  This
  143.      applies to `eval-defun', `eval-region', and `eval-current-buffer'.
  144.  
  145.      Use the command `edebug-all-defs' to toggle the value of this
  146.      variable. You may want to make this variable local to each buffer
  147.      by calling `(make-local-variable 'edebug-all-defs)' in your
  148.      `emacs-lisp-mode-hook'.
  149.  
  150.      The default value is `nil'.
  151.  
  152.  - User Option: edebug-all-forms
  153.      If non-`nil', normal evaluation of any forms by `eval-defun',
  154.      `eval-region', and `eval-current-buffer' will instrument them for
  155.      Edebug.
  156.  
  157.      Use the command `edebug-all-forms' to toggle the value of this
  158.      option.
  159.  
  160.  - User Option: edebug-save-windows
  161.      If non-`nil', save and restore window configuration on Edebug
  162.      calls.  It takes some time to save and restore, so if your program
  163.      does not care what happens to the window configurations, it is
  164.      better to set this variable to `nil'.
  165.  
  166.  - User Option: edebug-save-displayed-buffer-points
  167.      If non-`nil', save and restore point in all displayed buffers.
  168.      This is necessary if you are debugging code that changes the point
  169.      of a buffer which is displayed in a non-selected window.  If
  170.      Edebug or the user then selects the window, the buffer's point
  171.      will be changed to the window's point.
  172.  
  173.      This is an expensive operation since it visits each window and each
  174.      displayed buffer twice for each Edebug activation, so it is best to
  175.      avoid it if you can.
  176.  
  177.  - User Option: edebug-initial-mode
  178.      If this variable is non-`nil', it specifies the initial execution
  179.      mode for Edebug when it is first activated.  Possible values are
  180.      `step', `next', `go', `Go-nonstop', `trace', `Trace-fast',
  181.      `continue', and `Continue-fast'.
  182.  
  183.      The default value is `step'.
  184.  
  185.  - User Option: edebug-trace
  186.      Non-`nil' means display a trace of function entry and exit.
  187.      Tracing output is displayed in a buffer named `*edebug-trace*', one
  188.      function entry or exit per line, indented by the recursion level.
  189.      You can customize this display by replacing functions
  190.      `edebug-print-trace-before' and `edebug-print-trace-after'.
  191.  
  192.      The default value is `nil'.
  193.  
  194.  - User Option: edebug-test-coverage
  195.      If non-`nil', Edebug tests coverage of all expressions debugged.
  196.      This is done by comparing the result of each expression with the
  197.      previous result. Coverage is considered OK if two different
  198.      results are found.  So to sufficiently test the coverage of your
  199.      code, try to execute it under conditions that evaluate all
  200.      expressions more than once, and produce different results for each
  201.      expression.
  202.  
  203.      Use `edebug-display-freq-count' to display the frequency count and
  204.      coverage information for a definition.
  205.  
  206.  - User Option: edebug-continue-kbd-macro
  207.      If non-`nil', continue defining or executing any keyboard macro
  208.      that is executing outside of Edebug.
  209.  
  210.  - User Option: edebug-print-length
  211.      If non-`nil', set `print-length' to this while printing results in
  212.      Edebug.  The default value is `50'.
  213.  
  214.  - User Option: edebug-print-level
  215.      If non-`nil', set `print-level' to this while printing results in
  216.      Edebug.  The default value is `50'.
  217.  
  218.  - User Option: edebug-print-circle
  219.      If non-`nil', set `print-circle' to this while printing results in
  220.      Edebug.  The default value is `nil'.
  221.  
  222. 
  223. File: lispref.info,  Node: Read and Print,  Next: Minibuffers,  Prev: Debugging,  Up: Top
  224.  
  225. Reading and Printing Lisp Objects
  226. *********************************
  227.  
  228.    "Printing" and "reading" are the operations of converting Lisp
  229. objects to textual form and vice versa.  They use the printed
  230. representations and read syntax described in *Note Lisp Data Types::.
  231.  
  232.    This chapter describes the Lisp functions for reading and printing.
  233. It also describes "streams", which specify where to get the text (if
  234. reading) or where to put it (if printing).
  235.  
  236. * Menu:
  237.  
  238. * Streams Intro::     Overview of streams, reading and printing.
  239. * Input Streams::     Various data types that can be used as input streams.
  240. * Input Functions::   Functions to read Lisp objects from text.
  241. * Output Streams::    Various data types that can be used as output streams.
  242. * Output Functions::  Functions to print Lisp objects as text.
  243. * Output Variables::  Variables that control what the printing functions do.
  244.  
  245. 
  246. File: lispref.info,  Node: Streams Intro,  Next: Input Streams,  Up: Read and Print
  247.  
  248. Introduction to Reading and Printing
  249. ====================================
  250.  
  251.    "Reading" a Lisp object means parsing a Lisp expression in textual
  252. form and producing a corresponding Lisp object.  This is how Lisp
  253. programs get into Lisp from files of Lisp code.  We call the text the
  254. "read syntax" of the object.  For example, the text `(a . 5)' is the
  255. read syntax for a cons cell whose CAR is `a' and whose CDR is the
  256. number 5.
  257.  
  258.    "Printing" a Lisp object means producing text that represents that
  259. object--converting the object to its printed representation.  Printing
  260. the cons cell described above produces the text `(a . 5)'.
  261.  
  262.    Reading and printing are more or less inverse operations: printing
  263. the object that results from reading a given piece of text often
  264. produces the same text, and reading the text that results from printing
  265. an object usually produces a similar-looking object.  For example,
  266. printing the symbol `foo' produces the text `foo', and reading that text
  267. returns the symbol `foo'.  Printing a list whose elements are `a' and
  268. `b' produces the text `(a b)', and reading that text produces a list
  269. (but not the same list) with elements `a' and `b'.
  270.  
  271.    However, these two operations are not precisely inverses.  There are
  272. three kinds of exceptions:
  273.  
  274.    * Printing can produce text that cannot be read.  For example,
  275.      buffers, windows, frames, subprocesses and markers print into text
  276.      that starts with `#'; if you try to read this text, you get an
  277.      error.  There is no way to read those data types.
  278.  
  279.    * One object can have multiple textual representations.  For example,
  280.      `1' and `01' represent the same integer, and `(a b)' and `(a .
  281.      (b))' represent the same list.  Reading will accept any of the
  282.      alternatives, but printing must choose one of them.
  283.  
  284.    * Comments can appear at certain points in the middle of an object's
  285.      read sequence without affecting the result of reading it.
  286.  
  287. 
  288. File: lispref.info,  Node: Input Streams,  Next: Input Functions,  Prev: Streams Intro,  Up: Read and Print
  289.  
  290. Input Streams
  291. =============
  292.  
  293.    Most of the Lisp functions for reading text take an "input stream"
  294. as an argument.  The input stream specifies where or how to get the
  295. characters of the text to be read.  Here are the possible types of input
  296. stream:
  297.  
  298. BUFFER
  299.      The input characters are read from BUFFER, starting with the
  300.      character directly after point.  Point advances as characters are
  301.      read.
  302.  
  303. MARKER
  304.      The input characters are read from the buffer that MARKER is in,
  305.      starting with the character directly after the marker.  The marker
  306.      position advances as characters are read.  The value of point in
  307.      the buffer has no effect when the stream is a marker.
  308.  
  309. STRING
  310.      The input characters are taken from STRING, starting at the first
  311.      character in the string and using as many characters as required.
  312.  
  313. FUNCTION
  314.      The input characters are generated by FUNCTION, one character per
  315.      call.  Normally FUNCTION is called with no arguments, and should
  316.      return a character.
  317.  
  318.      Occasionally FUNCTION is called with one argument (always a
  319.      character).  When that happens, FUNCTION should save the argument
  320.      and arrange to return it on the next call.  This is called
  321.      "unreading" the character; it happens when the Lisp reader reads
  322.      one character too many and wants to "put it back where it came
  323.      from".
  324.  
  325. `t'
  326.      `t' used as a stream means that the input is read from the
  327.      minibuffer.  In fact, the minibuffer is invoked once and the text
  328.      given by the user is made into a string that is then used as the
  329.      input stream.
  330.  
  331. `nil'
  332.      `nil' supplied as an input stream means to use the value of
  333.      `standard-input' instead; that value is the "default input
  334.      stream", and must be a non-`nil' input stream.
  335.  
  336. SYMBOL
  337.      A symbol as input stream is equivalent to the symbol's function
  338.      definition (if any).
  339.  
  340.    Here is an example of reading from a stream that is a buffer, showing
  341. where point is located before and after:
  342.  
  343.      ---------- Buffer: foo ----------
  344.      This-!- is the contents of foo.
  345.      ---------- Buffer: foo ----------
  346.      
  347.      (read (get-buffer "foo"))
  348.           => is
  349.      (read (get-buffer "foo"))
  350.           => the
  351.      
  352.      ---------- Buffer: foo ----------
  353.      This is the-!- contents of foo.
  354.      ---------- Buffer: foo ----------
  355.  
  356. Note that the first read skips a space.  Reading skips any amount of
  357. whitespace preceding the significant text.
  358.  
  359.    In Emacs 18, reading a symbol discarded the delimiter terminating the
  360. symbol.  Thus, point would end up at the beginning of `contents' rather
  361. than after `the'.  The Emacs 19 behavior is superior because it
  362. correctly handles input such as `bar(foo)', where the open-parenthesis
  363. that ends one object is needed as the beginning of another object.
  364.  
  365.    Here is an example of reading from a stream that is a marker,
  366. initially positioned at the beginning of the buffer shown.  The value
  367. read is the symbol `This'.
  368.  
  369.  
  370.      ---------- Buffer: foo ----------
  371.      This is the contents of foo.
  372.      ---------- Buffer: foo ----------
  373.      
  374.      (setq m (set-marker (make-marker) 1 (get-buffer "foo")))
  375.           => #<marker at 1 in foo>
  376.      (read m)
  377.           => This
  378.      m
  379.           => #<marker at 5 in foo>   ;; Before the first space.
  380.  
  381.    Here we read from the contents of a string:
  382.  
  383.      (read "(When in) the course")
  384.           => (When in)
  385.  
  386.    The following example reads from the minibuffer.  The prompt is:
  387. `Lisp expression: '.  (That is always the prompt used when you read
  388. from the stream `t'.)  The user's input is shown following the prompt.
  389.  
  390.      (read t)
  391.           => 23
  392.      ---------- Buffer: Minibuffer ----------
  393.      Lisp expression: `23 RET'
  394.      ---------- Buffer: Minibuffer ----------
  395.  
  396.    Finally, here is an example of a stream that is a function, named
  397. `useless-stream'.  Before we use the stream, we initialize the variable
  398. `useless-list' to a list of characters.  Then each call to the function
  399. `useless-stream' obtains the next character in the list or unreads a
  400. character by adding it to the front of the list.
  401.  
  402.      (setq useless-list (append "XY()" nil))
  403.           => (88 89 40 41)
  404.      
  405.      (defun useless-stream (&optional unread)
  406.        (if unread
  407.            (setq useless-list (cons unread useless-list))
  408.          (prog1 (car useless-list)
  409.                 (setq useless-list (cdr useless-list)))))
  410.           => useless-stream
  411.  
  412. Now we read using the stream thus constructed:
  413.  
  414.      (read 'useless-stream)
  415.           => XY
  416.      
  417.      useless-list
  418.           => (40 41)
  419.  
  420. Note that the open and close parentheses remains in the list.  The Lisp
  421. reader encountered the open parenthesis, decided that it ended the
  422. input, and unread it.  Another attempt to read from the stream at this
  423. point would read `()' and return `nil'.
  424.  
  425.  - Function: get-file-char
  426.      This function is used internally as an input stream to read from
  427.      the input file opened by the function `load'.  Don't use this
  428.      function yourself.
  429.  
  430. 
  431. File: lispref.info,  Node: Input Functions,  Next: Output Streams,  Prev: Input Streams,  Up: Read and Print
  432.  
  433. Input Functions
  434. ===============
  435.  
  436.    This section describes the Lisp functions and variables that pertain
  437. to reading.
  438.  
  439.    In the functions below, STREAM stands for an input stream (see the
  440. previous section).  If STREAM is `nil' or omitted, it defaults to the
  441. value of `standard-input'.
  442.  
  443.    An `end-of-file' error is signaled if reading encounters an
  444. unterminated list, vector, or string.
  445.  
  446.  - Function: read &optional STREAM
  447.      This function reads one textual Lisp expression from STREAM,
  448.      returning it as a Lisp object.  This is the basic Lisp input
  449.      function.
  450.  
  451.  - Function: read-from-string STRING &optional START END
  452.      This function reads the first textual Lisp expression from the
  453.      text in STRING.  It returns a cons cell whose CAR is that
  454.      expression, and whose CDR is an integer giving the position of the
  455.      next remaining character in the string (i.e., the first one not
  456.      read).
  457.  
  458.      If START is supplied, then reading begins at index START in the
  459.      string (where the first character is at index 0).  If END is also
  460.      supplied, then reading stops just before that index, as if the rest
  461.      of the string were not there.
  462.  
  463.      For example:
  464.  
  465.           (read-from-string "(setq x 55) (setq y 5)")
  466.                => ((setq x 55) . 11)
  467.           (read-from-string "\"A short string\"")
  468.                => ("A short string" . 16)
  469.           
  470.           ;; Read starting at the first character.
  471.           (read-from-string "(list 112)" 0)
  472.                => ((list 112) . 10)
  473.           ;; Read starting at the second character.
  474.           (read-from-string "(list 112)" 1)
  475.                => (list . 5)
  476.           ;; Read starting at the seventh character,
  477.           ;;   and stopping at the ninth.
  478.           (read-from-string "(list 112)" 6 8)
  479.                => (11 . 8)
  480.  
  481.  - Variable: standard-input
  482.      This variable holds the default input stream--the stream that
  483.      `read' uses when the STREAM argument is `nil'.
  484.  
  485. 
  486. File: lispref.info,  Node: Output Streams,  Next: Output Functions,  Prev: Input Functions,  Up: Read and Print
  487.  
  488. Output Streams
  489. ==============
  490.  
  491.    An output stream specifies what to do with the characters produced
  492. by printing.  Most print functions accept an output stream as an
  493. optional argument.  Here are the possible types of output stream:
  494.  
  495. BUFFER
  496.      The output characters are inserted into BUFFER at point.  Point
  497.      advances as characters are inserted.
  498.  
  499. MARKER
  500.      The output characters are inserted into the buffer that MARKER
  501.      points into, at the marker position.  The marker position advances
  502.      as characters are inserted.  The value of point in the buffer has
  503.      no effect on printing when the stream is a marker.
  504.  
  505. FUNCTION
  506.      The output characters are passed to FUNCTION, which is responsible
  507.      for storing them away.  It is called with a single character as
  508.      argument, as many times as there are characters to be output, and
  509.      is free to do anything at all with the characters it receives.
  510.  
  511. `t'
  512.      The output characters are displayed in the echo area.
  513.  
  514. `nil'
  515.      `nil' specified as an output stream means to the value of
  516.      `standard-output' instead; that value is the "default output
  517.      stream", and must be a non-`nil' output stream.
  518.  
  519. SYMBOL
  520.      A symbol as output stream is equivalent to the symbol's function
  521.      definition (if any).
  522.  
  523.    Many of the valid output streams are also valid as input streams.
  524. The difference between input and output streams is therefore mostly one
  525. of how you use a Lisp object, not a distinction of types of object.
  526.  
  527.    Here is an example of a buffer used as an output stream.  Point is
  528. initially located as shown immediately before the `h' in `the'.  At the
  529. end, point is located directly before that same `h'.
  530.  
  531.      ---------- Buffer: foo ----------
  532.      This is t-!-he contents of foo.
  533.      ---------- Buffer: foo ----------
  534.      
  535.      (print "This is the output" (get-buffer "foo"))
  536.           => "This is the output"
  537.      
  538.      ---------- Buffer: foo ----------
  539.      This is t
  540.      "This is the output"
  541.      -!-he contents of foo.
  542.      ---------- Buffer: foo ----------
  543.  
  544.    Now we show a use of a marker as an output stream.  Initially, the
  545. marker is in buffer `foo', between the `t' and the `h' in the word
  546. `the'.  At the end, the marker has advanced over the inserted text so
  547. that it remains positioned before the same `h'.  Note that the location
  548. of point, shown in the usual fashion, has no effect.
  549.  
  550.      ---------- Buffer: foo ----------
  551.      "This is the -!-output"
  552.      ---------- Buffer: foo ----------
  553.      
  554.      m
  555.           => #<marker at 11 in foo>
  556.      
  557.      (print "More output for foo." m)
  558.           => "More output for foo."
  559.      
  560.      ---------- Buffer: foo ----------
  561.      "This is t
  562.      "More output for foo."
  563.      he -!-output"
  564.      ---------- Buffer: foo ----------
  565.      
  566.      m
  567.           => #<marker at 35 in foo>
  568.  
  569.    The following example shows output to the echo area:
  570.  
  571.      (print "Echo Area output" t)
  572.           => "Echo Area output"
  573.      ---------- Echo Area ----------
  574.      "Echo Area output"
  575.      ---------- Echo Area ----------
  576.  
  577.    Finally, we show the use of a function as an output stream.  The
  578. function `eat-output' takes each character that it is given and conses
  579. it onto the front of the list `last-output' (*note Building Lists::.).
  580. At the end, the list contains all the characters output, but in reverse
  581. order.
  582.  
  583.      (setq last-output nil)
  584.           => nil
  585.      
  586.      (defun eat-output (c)
  587.        (setq last-output (cons c last-output)))
  588.           => eat-output
  589.      
  590.      (print "This is the output" 'eat-output)
  591.           => "This is the output"
  592.      
  593.      last-output
  594.           => (10 34 116 117 112 116 117 111 32 101 104
  595.          116 32 115 105 32 115 105 104 84 34 10)
  596.  
  597. Now we can put the output in the proper order by reversing the list:
  598.  
  599.      (concat (nreverse last-output))
  600.           => "
  601.      \"This is the output\"
  602.      "
  603.  
  604. Calling `concat' converts the list to a string so you can see its
  605. contents more clearly.
  606.  
  607. 
  608. File: lispref.info,  Node: Output Functions,  Next: Output Variables,  Prev: Output Streams,  Up: Read and Print
  609.  
  610. Output Functions
  611. ================
  612.  
  613.    This section describes the Lisp functions for printing Lisp objects.
  614.  
  615.    Some of the XEmacs printing functions add quoting characters to the
  616. output when necessary so that it can be read properly.  The quoting
  617. characters used are `"' and `\'; they distinguish strings from symbols,
  618. and prevent punctuation characters in strings and symbols from being
  619. taken as delimiters when reading.  *Note Printed Representation::, for
  620. full details.  You specify quoting or no quoting by the choice of
  621. printing function.
  622.  
  623.    If the text is to be read back into Lisp, then it is best to print
  624. with quoting characters to avoid ambiguity.  Likewise, if the purpose is
  625. to describe a Lisp object clearly for a Lisp programmer.  However, if
  626. the purpose of the output is to look nice for humans, then it is better
  627. to print without quoting.
  628.  
  629.    Printing a self-referent Lisp object requires an infinite amount of
  630. text.  In certain cases, trying to produce this text leads to a stack
  631. overflow.  XEmacs detects such recursion and prints `#LEVEL' instead of
  632. recursively printing an object already being printed.  For example,
  633. here `#0' indicates a recursive reference to the object at level 0 of
  634. the current print operation:
  635.  
  636.      (setq foo (list nil))
  637.           => (nil)
  638.      (setcar foo foo)
  639.           => (#0)
  640.  
  641.    In the functions below, STREAM stands for an output stream.  (See
  642. the previous section for a description of output streams.)  If STREAM
  643. is `nil' or omitted, it defaults to the value of `standard-output'.
  644.  
  645.  - Function: print OBJECT &optional STREAM
  646.      The `print' function is a convenient way of printing.  It outputs
  647.      the printed representation of OBJECT to STREAM, printing in
  648.      addition one newline before OBJECT and another after it.  Quoting
  649.      characters are used.  `print' returns OBJECT.  For example:
  650.  
  651.           (progn (print 'The\ cat\ in)
  652.                  (print "the hat")
  653.                  (print " came back"))
  654.                -|
  655.                -| The\ cat\ in
  656.                -|
  657.                -| "the hat"
  658.                -|
  659.                -| " came back"
  660.                -|
  661.                => " came back"
  662.  
  663.  - Function: prin1 OBJECT &optional STREAM
  664.      This function outputs the printed representation of OBJECT to
  665.      STREAM.  It does not print newlines to separate output as `print'
  666.      does, but it does use quoting characters just like `print'.  It
  667.      returns OBJECT.
  668.  
  669.           (progn (prin1 'The\ cat\ in)
  670.                  (prin1 "the hat")
  671.                  (prin1 " came back"))
  672.                -| The\ cat\ in"the hat"" came back"
  673.                => " came back"
  674.  
  675.  - Function: princ OBJECT &optional STREAM
  676.      This function outputs the printed representation of OBJECT to
  677.      STREAM.  It returns OBJECT.
  678.  
  679.      This function is intended to produce output that is readable by
  680.      people, not by `read', so it doesn't insert quoting characters and
  681.      doesn't put double-quotes around the contents of strings.  It does
  682.      not add any spacing between calls.
  683.  
  684.           (progn
  685.             (princ 'The\ cat)
  686.             (princ " in the \"hat\""))
  687.                -| The cat in the "hat"
  688.                => " in the \"hat\""
  689.  
  690.  - Function: terpri &optional STREAM
  691.      This function outputs a newline to STREAM.  The name stands for
  692.      "terminate print".
  693.  
  694.  - Function: write-char CHARACTER &optional STREAM
  695.      This function outputs CHARACTER to STREAM.  It returns CHARACTER.
  696.  
  697.  - Function: prin1-to-string OBJECT &optional NOESCAPE
  698.      This function returns a string containing the text that `prin1'
  699.      would have printed for the same argument.
  700.  
  701.           (prin1-to-string 'foo)
  702.                => "foo"
  703.           (prin1-to-string (mark-marker))
  704.                => "#<marker at 2773 in strings.texi>"
  705.  
  706.      If NOESCAPE is non-`nil', that inhibits use of quoting characters
  707.      in the output.  (This argument is supported in Emacs versions 19
  708.      and later.)
  709.  
  710.           (prin1-to-string "foo")
  711.                => "\"foo\""
  712.           (prin1-to-string "foo" t)
  713.                => "foo"
  714.  
  715.      See `format', in *Note String Conversion::, for other ways to
  716.      obtain the printed representation of a Lisp object as a string.
  717.  
  718. 
  719. File: lispref.info,  Node: Output Variables,  Prev: Output Functions,  Up: Read and Print
  720.  
  721. Variables Affecting Output
  722. ==========================
  723.  
  724.  - Variable: standard-output
  725.      The value of this variable is the default output stream--the stream
  726.      that print functions use when the STREAM argument is `nil'.
  727.  
  728.  - Variable: print-escape-newlines
  729.      If this variable is non-`nil', then newline characters in strings
  730.      are printed as `\n' and formfeeds are printed as `\f'.  Normally
  731.      these characters are printed as actual newlines and formfeeds.
  732.  
  733.      This variable affects the print functions `prin1' and `print', as
  734.      well as everything that uses them.  It does not affect `princ'.
  735.      Here is an example using `prin1':
  736.  
  737.           (prin1 "a\nb")
  738.                -| "a
  739.                -| b"
  740.                => "a
  741.           b"
  742.           
  743.           (let ((print-escape-newlines t))
  744.             (prin1 "a\nb"))
  745.                -| "a\nb"
  746.                => "a
  747.           b"
  748.  
  749.      In the second expression, the local binding of
  750.      `print-escape-newlines' is in effect during the call to `prin1',
  751.      but not during the printing of the result.
  752.  
  753.  - Variable: print-length
  754.      The value of this variable is the maximum number of elements of a
  755.      list that will be printed.  If a list being printed has more than
  756.      this many elements, it is abbreviated with an ellipsis.
  757.  
  758.      If the value is `nil' (the default), then there is no limit.
  759.  
  760.           (setq print-length 2)
  761.                => 2
  762.           (print '(1 2 3 4 5))
  763.                -| (1 2 ...)
  764.                => (1 2 ...)
  765.  
  766.  - Variable: print-level
  767.      The value of this variable is the maximum depth of nesting of
  768.      parentheses and brackets when printed.  Any list or vector at a
  769.      depth exceeding this limit is abbreviated with an ellipsis.  A
  770.      value of `nil' (which is the default) means no limit.
  771.  
  772.      This variable exists in version 19 and later versions.
  773.  
  774. 
  775. File: lispref.info,  Node: Minibuffers,  Next: Command Loop,  Prev: Read and Print,  Up: Top
  776.  
  777. Minibuffers
  778. ***********
  779.  
  780.    A "minibuffer" is a special buffer that XEmacs commands use to read
  781. arguments more complicated than the single numeric prefix argument.
  782. These arguments include file names, buffer names, and command names (as
  783. in `M-x').  The minibuffer is displayed on the bottom line of the
  784. frame, in the same place as the echo area, but only while it is in use
  785. for reading an argument.
  786.  
  787. * Menu:
  788.  
  789. * Intro to Minibuffers::      Basic information about minibuffers.
  790. * Text from Minibuffer::      How to read a straight text string.
  791. * Object from Minibuffer::    How to read a Lisp object or expression.
  792. * Minibuffer History::          Recording previous minibuffer inputs
  793.                 so the user can reuse them.
  794. * Completion::                How to invoke and customize completion.
  795. * Yes-or-No Queries::         Asking a question with a simple answer.
  796. * Multiple Queries::          Asking a series of similar questions.
  797. * Minibuffer Misc::           Various customization hooks and variables.
  798.  
  799. 
  800. File: lispref.info,  Node: Intro to Minibuffers,  Next: Text from Minibuffer,  Up: Minibuffers
  801.  
  802. Introduction to Minibuffers
  803. ===========================
  804.  
  805.    In most ways, a minibuffer is a normal XEmacs buffer.  Most
  806. operations *within* a buffer, such as editing commands, work normally
  807. in a minibuffer.  However, many operations for managing buffers do not
  808. apply to minibuffers.  The name of a minibuffer always has the form
  809. ` *Minibuf-NUMBER', and it cannot be changed.  Minibuffers are
  810. displayed only in special windows used only for minibuffers; these
  811. windows always appear at the bottom of a frame.  (Sometime frames have
  812. no minibuffer window, and sometimes a special kind of frame contains
  813. nothing but a minibuffer window; see *Note Minibuffers and Frames::.)
  814.  
  815.    The minibuffer's window is normally a single line.  You can resize it
  816. temporarily with the window sizing commands; it reverts to its normal
  817. size when the minibuffer is exited.  You can resize it permanently by
  818. using the window sizing commands in the frame's other window, when the
  819. minibuffer is not active.  If the frame contains just a minibuffer, you
  820. can change the minibuffer's size by changing the frame's size.
  821.  
  822.    If a command uses a minibuffer while there is an active minibuffer,
  823. this is called a "recursive minibuffer".  The first minibuffer is named
  824. ` *Minibuf-0*'.  Recursive minibuffers are named by incrementing the
  825. number at the end of the name.  (The names begin with a space so that
  826. they won't show up in normal buffer lists.)  Of several recursive
  827. minibuffers, the innermost (or most recently entered) is the active
  828. minibuffer.  We usually call this "the" minibuffer.  You can permit or
  829. forbid recursive minibuffers by setting the variable
  830. `enable-recursive-minibuffers' or by putting properties of that name on
  831. command symbols (*note Minibuffer Misc::.).
  832.  
  833.    Like other buffers, a minibuffer may use any of several local keymaps
  834. (*note Keymaps::.); these contain various exit commands and in some
  835. cases completion commands (*note Completion::.).
  836.  
  837.    * `minibuffer-local-map' is for ordinary input (no completion).
  838.  
  839.    * `minibuffer-local-ns-map' is similar, except that SPC exits just
  840.      like RET.  This is used mainly for Mocklisp compatibility.
  841.  
  842.    * `minibuffer-local-completion-map' is for permissive completion.
  843.  
  844.    * `minibuffer-local-must-match-map' is for strict completion and for
  845.      cautious completion.
  846.  
  847. 
  848. File: lispref.info,  Node: Text from Minibuffer,  Next: Object from Minibuffer,  Prev: Intro to Minibuffers,  Up: Minibuffers
  849.  
  850. Reading Text Strings with the Minibuffer
  851. ========================================
  852.  
  853.    Most often, the minibuffer is used to read text as a string.  It can
  854. also be used to read a Lisp object in textual form.  The most basic
  855. primitive for minibuffer input is `read-from-minibuffer'; it can do
  856. either one.
  857.  
  858.    In most cases, you should not call minibuffer input functions in the
  859. middle of a Lisp function.  Instead, do all minibuffer input as part of
  860. reading the arguments for a command, in the `interactive' spec.  *Note
  861. Defining Commands::.
  862.  
  863.  - Function: read-from-minibuffer PROMPT-STRING &optional
  864.           INITIAL-CONTENTS KEYMAP READ HIST
  865.      This function is the most general way to get input through the
  866.      minibuffer.  By default, it accepts arbitrary text and returns it
  867.      as a string; however, if READ is non-`nil', then it uses `read' to
  868.      convert the text into a Lisp object (*note Input Functions::.).
  869.  
  870.      The first thing this function does is to activate a minibuffer and
  871.      display it with PROMPT-STRING as the prompt.  This value must be a
  872.      string.
  873.  
  874.      Then, if INITIAL-CONTENTS is a string, `read-from-minibuffer'
  875.      inserts it into the minibuffer, leaving point at the end.  The
  876.      minibuffer appears with this text as its contents.
  877.  
  878.      The value of INITIAL-CONTENTS may also be a cons cell of the form
  879.      `(STRING . POSITION)'.  This means to insert STRING in the
  880.      minibuffer but put point POSITION characters from the beginning,
  881.      rather than at the end.
  882.  
  883.      If KEYMAP is non-`nil', that keymap is the local keymap to use in
  884.      the minibuffer.  If KEYMAP is omitted or `nil', the value of
  885.      `minibuffer-local-map' is used as the keymap.  Specifying a keymap
  886.      is the most important way to customize the minibuffer for various
  887.      applications such as completion.
  888.  
  889.      The argument HIST specifies which history list variable to use for
  890.      saving the input and for history commands used in the minibuffer.
  891.      It defaults to `minibuffer-history'.  *Note Minibuffer History::.
  892.  
  893.      When the user types a command to exit the minibuffer,
  894.      `read-from-minibuffer' uses the text in the minibuffer to produce
  895.      its return value.  Normally it simply makes a string containing
  896.      that text.  However, if READ is non-`nil', `read-from-minibuffer'
  897.      reads the text and returns the resulting Lisp object, unevaluated.
  898.      (*Note Input Functions::, for information about reading.)
  899.  
  900.  - Function: read-string PROMPT &optional INITIAL
  901.      This function reads a string from the minibuffer and returns it.
  902.      The arguments PROMPT and INITIAL are used as in
  903.      `read-from-minibuffer'.  The keymap used is `minibuffer-local-map'.
  904.  
  905.      This is a simplified interface to the `read-from-minibuffer'
  906.      function:
  907.  
  908.           (read-string PROMPT INITIAL)
  909.           ==
  910.           (read-from-minibuffer PROMPT INITIAL nil nil nil)
  911.  
  912.  - Variable: minibuffer-local-map
  913.      This is the default local keymap for reading from the minibuffer.
  914.      By default, it makes the following bindings:
  915.  
  916.     LFD
  917.           `exit-minibuffer'
  918.  
  919.     RET
  920.           `exit-minibuffer'
  921.  
  922.     `C-g'
  923.           `abort-recursive-edit'
  924.  
  925.     `M-n'
  926.           `next-history-element'
  927.  
  928.     `M-p'
  929.           `previous-history-element'
  930.  
  931.     `M-r'
  932.           `next-matching-history-element'
  933.  
  934.     `M-s'
  935.           `previous-matching-history-element'
  936.  
  937.  - Function: read-no-blanks-input PROMPT &optional INITIAL
  938.      This function reads a string from the minibuffer, but does not
  939.      allow whitespace characters as part of the input: instead, those
  940.      characters terminate the input.  The arguments PROMPT and INITIAL
  941.      are used as in `read-from-minibuffer'.
  942.  
  943.      This is a simplified interface to the `read-from-minibuffer'
  944.      function, and passes the value of the `minibuffer-local-ns-map'
  945.      keymap as the KEYMAP argument for that function.  Since the keymap
  946.      `minibuffer-local-ns-map' does not rebind `C-q', it *is* possible
  947.      to put a space into the string, by quoting it.
  948.  
  949.           (read-no-blanks-input PROMPT INITIAL)
  950.           ==
  951.           (read-from-minibuffer PROMPT INITIAL minibuffer-local-ns-map)
  952.  
  953.  - Variable: minibuffer-local-ns-map
  954.      This built-in variable is the keymap used as the minibuffer local
  955.      keymap in the function `read-no-blanks-input'.  By default, it
  956.      makes the following bindings, in addition to those of
  957.      `minibuffer-local-map':
  958.  
  959.     SPC
  960.           `exit-minibuffer'
  961.  
  962.     TAB
  963.           `exit-minibuffer'
  964.  
  965.     `?'
  966.           `self-insert-and-exit'
  967.  
  968. 
  969. File: lispref.info,  Node: Object from Minibuffer,  Next: Minibuffer History,  Prev: Text from Minibuffer,  Up: Minibuffers
  970.  
  971. Reading Lisp Objects with the Minibuffer
  972. ========================================
  973.  
  974.    This section describes functions for reading Lisp objects with the
  975. minibuffer.
  976.  
  977.  - Function: read-minibuffer PROMPT &optional INITIAL
  978.      This function reads a Lisp object in the minibuffer and returns it,
  979.      without evaluating it.  The arguments PROMPT and INITIAL are used
  980.      as in `read-from-minibuffer'.
  981.  
  982.      This is a simplified interface to the `read-from-minibuffer'
  983.      function:
  984.  
  985.           (read-minibuffer PROMPT INITIAL)
  986.           ==
  987.           (read-from-minibuffer PROMPT INITIAL nil t)
  988.  
  989.      Here is an example in which we supply the string `"(testing)"' as
  990.      initial input:
  991.  
  992.           (read-minibuffer
  993.            "Enter an expression: " (format "%s" '(testing)))
  994.           
  995.           ;; Here is how the minibuffer is displayed:
  996.  
  997.           ---------- Buffer: Minibuffer ----------
  998.           Enter an expression: (testing)-!-
  999.           ---------- Buffer: Minibuffer ----------
  1000.  
  1001.      The user can type RET immediately to use the initial input as a
  1002.      default, or can edit the input.
  1003.  
  1004.  - Function: eval-minibuffer PROMPT &optional INITIAL
  1005.      This function reads a Lisp expression in the minibuffer, evaluates
  1006.      it, then returns the result.  The arguments PROMPT and INITIAL are
  1007.      used as in `read-from-minibuffer'.
  1008.  
  1009.      This function simply evaluates the result of a call to
  1010.      `read-minibuffer':
  1011.  
  1012.           (eval-minibuffer PROMPT INITIAL)
  1013.           ==
  1014.           (eval (read-minibuffer PROMPT INITIAL))
  1015.  
  1016.  - Function: edit-and-eval-command PROMPT FORM
  1017.      This function reads a Lisp expression in the minibuffer, and then
  1018.      evaluates it.  The difference between this command and
  1019.      `eval-minibuffer' is that here the initial FORM is not optional
  1020.      and it is treated as a Lisp object to be converted to printed
  1021.      representation rather than as a string of text.  It is printed with
  1022.      `prin1', so if it is a string, double-quote characters (`"')
  1023.      appear in the initial text.  *Note Output Functions::.
  1024.  
  1025.      The first thing `edit-and-eval-command' does is to activate the
  1026.      minibuffer with PROMPT as the prompt.  Then it inserts the printed
  1027.      representation of FORM in the minibuffer, and lets the user edit.
  1028.      When the user exits the minibuffer, the edited text is read with
  1029.      `read' and then evaluated.  The resulting value becomes the value
  1030.      of `edit-and-eval-command'.
  1031.  
  1032.      In the following example, we offer the user an expression with
  1033.      initial text which is a valid form already:
  1034.  
  1035.           (edit-and-eval-command "Please edit: " '(forward-word 1))
  1036.           
  1037.           ;; After evaluation of the preceding expression,
  1038.           ;;   the following appears in the minibuffer:
  1039.  
  1040.           ---------- Buffer: Minibuffer ----------
  1041.           Please edit: (forward-word 1)-!-
  1042.           ---------- Buffer: Minibuffer ----------
  1043.  
  1044.      Typing RET right away would exit the minibuffer and evaluate the
  1045.      expression, thus moving point forward one word.
  1046.      `edit-and-eval-command' returns `nil' in this example.
  1047.  
  1048. 
  1049. File: lispref.info,  Node: Minibuffer History,  Next: Completion,  Prev: Object from Minibuffer,  Up: Minibuffers
  1050.  
  1051. Minibuffer History
  1052. ==================
  1053.  
  1054.    A "minibuffer history list" records previous minibuffer inputs so
  1055. the user can reuse them conveniently.  A history list is actually a
  1056. symbol, not a list; it is a variable whose value is a list of strings
  1057. (previous inputs), most recent first.
  1058.  
  1059.    There are many separate history lists, used for different kinds of
  1060. inputs.  It's the Lisp programmer's job to specify the right history
  1061. list for each use of the minibuffer.
  1062.  
  1063.    The basic minibuffer input functions `read-from-minibuffer' and
  1064. `completing-read' both accept an optional argument named HIST which is
  1065. how you specify the history list.  Here are the possible values:
  1066.  
  1067. VARIABLE
  1068.      Use VARIABLE (a symbol) as the history list.
  1069.  
  1070. (VARIABLE . STARTPOS)
  1071.      Use VARIABLE (a symbol) as the history list, and assume that the
  1072.      initial history position is STARTPOS (an integer, counting from
  1073.      zero which specifies the most recent element of the history).
  1074.  
  1075.      If you specify STARTPOS, then you should also specify that element
  1076.      of the history as the initial minibuffer contents, for consistency.
  1077.  
  1078.    If you don't specify HIST, then the default history list
  1079. `minibuffer-history' is used.  For other standard history lists, see
  1080. below.  You can also create your own history list variable; just
  1081. initialize it to `nil' before the first use.
  1082.  
  1083.    Both `read-from-minibuffer' and `completing-read' add new elements
  1084. to the history list automatically, and provide commands to allow the
  1085. user to reuse items on the list.  The only thing your program needs to
  1086. do to use a history list is to initialize it and to pass its name to
  1087. the input functions when you wish.  But it is safe to modify the list
  1088. by hand when the minibuffer input functions are not using it.
  1089.  
  1090.  - Variable: minibuffer-history
  1091.      The default history list for minibuffer history input.
  1092.  
  1093.  - Variable: query-replace-history
  1094.      A history list for arguments to `query-replace' (and similar
  1095.      arguments to other commands).
  1096.  
  1097.  - Variable: file-name-history
  1098.      A history list for file name arguments.
  1099.  
  1100.  - Variable: regexp-history
  1101.      A history list for regular expression arguments.
  1102.  
  1103.  - Variable: extended-command-history
  1104.      A history list for arguments that are names of extended commands.
  1105.  
  1106.  - Variable: shell-command-history
  1107.      A history list for arguments that are shell commands.
  1108.  
  1109.  - Variable: read-expression-history
  1110.      A history list for arguments that are Lisp expressions to evaluate.
  1111.  
  1112. 
  1113. File: lispref.info,  Node: Completion,  Next: Yes-or-No Queries,  Prev: Minibuffer History,  Up: Minibuffers
  1114.  
  1115. Completion
  1116. ==========
  1117.  
  1118.    "Completion" is a feature that fills in the rest of a name starting
  1119. from an abbreviation for it.  Completion works by comparing the user's
  1120. input against a list of valid names and determining how much of the
  1121. name is determined uniquely by what the user has typed.  For example,
  1122. when you type `C-x b' (`switch-to-buffer') and then type the first few
  1123. letters of the name of the buffer to which you wish to switch, and then
  1124. type TAB (`minibuffer-complete'), Emacs extends the name as far as it
  1125. can.
  1126.  
  1127.    Standard XEmacs commands offer completion for names of symbols,
  1128. files, buffers, and processes; with the functions in this section, you
  1129. can implement completion for other kinds of names.
  1130.  
  1131.    The `try-completion' function is the basic primitive for completion:
  1132. it returns the longest determined completion of a given initial string,
  1133. with a given set of strings to match against.
  1134.  
  1135.    The function `completing-read' provides a higher-level interface for
  1136. completion.  A call to `completing-read' specifies how to determine the
  1137. list of valid names.  The function then activates the minibuffer with a
  1138. local keymap that binds a few keys to commands useful for completion.
  1139. Other functions provide convenient simple interfaces for reading
  1140. certain kinds of names with completion.
  1141.  
  1142. * Menu:
  1143.  
  1144. * Basic Completion::       Low-level functions for completing strings.
  1145.                              (These are too low level to use the minibuffer.)
  1146. * Minibuffer Completion::  Invoking the minibuffer with completion.
  1147. * Completion Commands::    Minibuffer commands that do completion.
  1148. * High-Level Completion::  Convenient special cases of completion
  1149.                              (reading buffer name, file name, etc.)
  1150. * Reading File Names::     Using completion to read file names.
  1151. * Programmed Completion::  Finding the completions for a given file name.
  1152.  
  1153. 
  1154. File: lispref.info,  Node: Basic Completion,  Next: Minibuffer Completion,  Up: Completion
  1155.  
  1156. Basic Completion Functions
  1157. --------------------------
  1158.  
  1159.    The two functions `try-completion' and `all-completions' have
  1160. nothing in themselves to do with minibuffers.  We describe them in this
  1161. chapter so as to keep them near the higher-level completion features
  1162. that do use the minibuffer.
  1163.  
  1164.  - Function: try-completion STRING COLLECTION &optional PREDICATE
  1165.      This function returns the longest common substring of all possible
  1166.      completions of STRING in COLLECTION.  The value of COLLECTION must
  1167.      be an alist, an obarray, or a function that implements a virtual
  1168.      set of strings (see below).
  1169.  
  1170.      Completion compares STRING against each of the permissible
  1171.      completions specified by COLLECTION; if the beginning of the
  1172.      permissible completion equals STRING, it matches.  If no
  1173.      permissible completions match, `try-completion' returns `nil'.  If
  1174.      only one permissible completion matches, and the match is exact,
  1175.      then `try-completion' returns `t'.  Otherwise, the value is the
  1176.      longest initial sequence common to all the permissible completions
  1177.      that match.
  1178.  
  1179.      If COLLECTION is an alist (*note Association Lists::.), the CARs
  1180.      of the alist elements form the set of permissible completions.
  1181.  
  1182.      If COLLECTION is an obarray (*note Creating Symbols::.), the names
  1183.      of all symbols in the obarray form the set of permissible
  1184.      completions.  The global variable `obarray' holds an obarray
  1185.      containing the names of all interned Lisp symbols.
  1186.  
  1187.      Note that the only valid way to make a new obarray is to create it
  1188.      empty and then add symbols to it one by one using `intern'.  Also,
  1189.      you cannot intern a given symbol in more than one obarray.
  1190.  
  1191.      If the argument PREDICATE is non-`nil', then it must be a function
  1192.      of one argument.  It is used to test each possible match, and the
  1193.      match is accepted only if PREDICATE returns non-`nil'.  The
  1194.      argument given to PREDICATE is either a cons cell from the alist
  1195.      (the CAR of which is a string) or else it is a symbol (*not* a
  1196.      symbol name) from the obarray.
  1197.  
  1198.      You can also use a symbol that is a function as COLLECTION.  Then
  1199.      the function is solely responsible for performing completion;
  1200.      `try-completion' returns whatever this function returns.  The
  1201.      function is called with three arguments: STRING, PREDICATE and
  1202.      `nil'.  (The reason for the third argument is so that the same
  1203.      function can be used in `all-completions' and do the appropriate
  1204.      thing in either case.)  *Note Programmed Completion::.
  1205.  
  1206.      In the first of the following examples, the string `foo' is
  1207.      matched by three of the alist CARs.  All of the matches begin with
  1208.      the characters `fooba', so that is the result.  In the second
  1209.      example, there is only one possible match, and it is exact, so the
  1210.      value is `t'.
  1211.  
  1212.           (try-completion
  1213.            "foo"
  1214.            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4)))
  1215.                => "fooba"
  1216.  
  1217.           (try-completion "foo" '(("barfoo" 2) ("foo" 3)))
  1218.                => t
  1219.  
  1220.      In the following example, numerous symbols begin with the
  1221.      characters `forw', and all of them begin with the word `forward'.
  1222.      In most of the symbols, this is followed with a `-', but not in
  1223.      all, so no more than `forward' can be completed.
  1224.  
  1225.           (try-completion "forw" obarray)
  1226.                => "forward"
  1227.  
  1228.      Finally, in the following example, only two of the three possible
  1229.      matches pass the predicate `test' (the string `foobaz' is too
  1230.      short).  Both of those begin with the string `foobar'.
  1231.  
  1232.           (defun test (s)
  1233.             (> (length (car s)) 6))
  1234.                => test
  1235.  
  1236.           (try-completion
  1237.            "foo"
  1238.            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  1239.            'test)
  1240.                => "foobar"
  1241.  
  1242.  - Function: all-completions STRING COLLECTION &optional PREDICATE
  1243.           NOSPACE
  1244.      This function returns a list of all possible completions of
  1245.      STRING.  The parameters to this function are the same as to
  1246.      `try-completion'.
  1247.  
  1248.      If COLLECTION is a function, it is called with three arguments:
  1249.      STRING, PREDICATE and `t'; then `all-completions' returns whatever
  1250.      the function returns.  *Note Programmed Completion::.
  1251.  
  1252.      If NOSPACE is non-`nil', completions that start with a space are
  1253.      ignored unless STRING also starts with a space.
  1254.  
  1255.      Here is an example, using the function `test' shown in the example
  1256.      for `try-completion':
  1257.  
  1258.           (defun test (s)
  1259.             (> (length (car s)) 6))
  1260.                => test
  1261.  
  1262.           (all-completions
  1263.            "foo"
  1264.            '(("foobar1" 1) ("barfoo" 2) ("foobaz" 3) ("foobar2" 4))
  1265.            'test)
  1266.                => ("foobar1" "foobar2")
  1267.  
  1268.  - Variable: completion-ignore-case
  1269.      If the value of this variable is non-`nil', XEmacs does not
  1270.      consider case significant in completion.
  1271.  
  1272.